//
//  WNTabBarController.swift
//  WNWeibo
//
//  Created by 风不会停息 on 2017/7/22.
//  Copyright © 2017年 风不会停息. All rights reserved.
//

import UIKit

class WNTabBarController: UITabBarController ,addButtonDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置自定义tabbar
        let TabBar = WNTabBar()
        
        self.setValue(TabBar, forKey: "tabBar")
        
        //addbutton点击发送闭包接收
        TabBar.addButtonClosuer = { [unowned self] in
            
            let composeView = WNComposeView()
            
            let window = UIApplication.shared.keyWindow
            
            window?.addSubview(composeView)
        }
        
        TabBar.addDelegate = self

        addChildViewController(WNHomeViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(WNMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(WNDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(WNMineTableViewController(), title: "我的", imageName: "tabbar_profile")
    }

    func clickAddButtonDe() {
        
        print("代理传")
    }

    func addChildViewController(_ childController: UIViewController, title : String , imageName : String) {
        
        
        childController.title = title
        
        //设置图片并取消选染色
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: .normal)
        
        let nav = WNNavViewController(rootViewController: childController)
        
        addChildViewController(nav)
    }

}
